package logic

import (
	"context"
	"hom/models/mysql"

	"hom/homrpc/homrpc"
	"hom/homrpc/internal/svc"

	"github.com/zeromicro/go-zero/core/logx"
)

type ShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *ShowLogic {
	return &ShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

func (l *ShowLogic) Show(in *homrpc.ShowRequest) (*homrpc.ShowResponse, error) {
	// todo: add your logic here and delete this line
	var hom mysql.Hom
	mysql.DB.Debug().Where("id=?", in.HomId).Find(&hom)

	return &homrpc.ShowResponse{
		Title: hom.Title,
		Image: hom.Image,
		Text:  hom.Text,
		Price: float32(hom.Price),
	}, nil
}
